<template>
  <lay-layout class="example">
    <lay-header>
      <v-menu :list="menuList">
        <template #search>
          <lay-input size="md" placeholder="搜索" v-model="keyword" style="width: 350px" @keydown.enter="hangleClick" allow-clear></lay-input>
          <svg-icon icon-name="search" class="search hover-color" @click="hangleClick"></svg-icon>
        </template>
      </v-menu>
    </lay-header>
    <lay-body>
      <router-view></router-view>
    </lay-body>
    <lay-footer></lay-footer>
    <lay-backtop></lay-backtop>
  </lay-layout>
</template>

<script setup>
import emitter from '@/utils/event'
import { ref } from "vue"
import { useRoute, useRouter } from "vue-router"

const route =useRoute()
const router = useRouter()
const keyword=ref('')
const menuList = [
  { name: '首页', path: '/home' },
  { name: '歌单', path: '/songList' },
  { name: '歌手', path: '/songer' },
  { slot: 'search', path: '/search' }
]
function hangleClick(){
  let push=router.push
  if(route.path==='/search') push=router.replace
  push({
    name:'search',
    query:{
      keyword:keyword.value
    }
  }).then(()=>{
    emitter.emit('search',keyword.value)
  })
}
</script>

<style lang="scss" scoped>
.search{
  margin-left: 10px;
  width: 30px;
  height: 30px;
  color: #bfbfbf;
}
</style>
